package com.cmcc.xdr.message;

import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.cmcc.xdr.entity.SrvccEntity;
import com.cmcc.xdr.util.TBCDUtil;

public class SingleSigSrvccMsg extends SingleSigMsg {

	public SrvccEntity srvcc = new SrvccEntity();

	private static SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

	public SingleSigSrvccMsg(ByteBuffer buffer,SingleSigGlobalMsg globalMsg) {
		this.setBuffer(buffer);
		this.setSSGMsg(globalMsg);

		srvcc.setLength(globalMsg.getTotalLength());
//		srvcc.setCity(globalMsg.getCity());
		srvcc.setLocalProvince(globalMsg.getLocalProvince());
		srvcc.setLocalCity(globalMsg.getLocalCity());
		srvcc.setOwnerProvince(globalMsg.getOwnerProvince());
		srvcc.setOwnerCity(globalMsg.getOwnerCity());
		srvcc.setRoamingType(globalMsg.getRoamingType());
		
		srvcc.setInterFace(globalMsg.getInterfaceType());
		srvcc.setXdrId(globalMsg.getXdrID());
		srvcc.setRat(globalMsg.getRat());
		srvcc.setImsi(globalMsg.getImsi());
		srvcc.setImei(globalMsg.getImei());
		srvcc.setMsisdn(globalMsg.getMsisdn());

		srvcc.setProcedureType(loadInt(1));
		srvcc.setProcedureStartTime(new Date(loadLong(8)));
		srvcc.setProcedureEndTime(new Date(loadLong(8)));

		srvcc.setSourceNeIp(loadIp(16));

		srvcc.setSourceNePort(loadInt(2));
		srvcc.setDestNeIp(loadIp(16));
		srvcc.setDestNePort(loadInt(2));
		srvcc.setRoamDirection(loadInt2(1));
		srvcc.setHomeMcc(loadInt(2));
		srvcc.setHomeMnc(loadInt(2));
		srvcc.setMcc(loadInt(2));
		srvcc.setMnc(loadInt(2));
		srvcc.setTargetLac(loadInt(2));
		srvcc.setSourceTac(loadStrInt(2));
//		srvcc.setSourceEci(loadInt(28) + "");
		srvcc.setSourceEci(loadStrInt(4));//之前的长度有变化之前为28
		srvcc.setSvFlags(loadInt(1));
		// 1+8+8+8+4+16+64+64+1+16+2+1+16+2+1+64+64+64+64=468

		srvcc.setUlCMscIp(loadIp(16));
		srvcc.setDlCMmeIp(loadIp(16));
		srvcc.setUlCMscTeid(loadHexStr(4));
		srvcc.setDlCMmeTeid(loadHexStr(4));
		srvcc.setStnSr(TBCDUtil.toTBCD(loadByte(24)));
		srvcc.setTargetRncId(loadHexStr(2));
		srvcc.setTargetCellId(loadHexStr(2));
		srvcc.setArp(loadInt(1));
		srvcc.setRequestResult(loadInt(1));
		srvcc.setResult(loadInt2(1));
		srvcc.setSvCause(loadInt(1));
		srvcc.setPostFailureCause(loadInt(1));
		srvcc.setRespDelay(loadInt(4));
		srvcc.setSvDelay(loadInt(4));

		srvcc.setInsertDate(format.format(new Date()));

		// dbtest.saveSrvcc(srvcc);
	}

	public SrvccEntity getSrvcc() {
		return srvcc;
	}

	public void setSrvcc(SrvccEntity srvcc) {
		this.srvcc = srvcc;
	}

}